<!DOCTYPE html>
<html>
<head>
   
</head>
<body>
 <h2>ES6-2DEMO演示</h2>
</body>
<script>
    function sum(x,y,z) {
        let total = 0;
        if (x)total += x;
        if (y) total += y;
        if (z) total += z;
        console.log(`total1:${total}`);        
    }
    
    function sum2(...m) {
        let total = 0;
        for(var i of m){
            console.log(m)
            total += i
        }
        console.log(`total2:${total}`);
    }
    sum2(4,8,9,10)

    let sum3 = (...m) => {
        let total = 0;
        for (var i of m) {
            console.log(m)
            total += i
        }
        console.log(`total3:${total}`);
    }
    sum3(5,9,6,4);

    var [x,y] = [4,8];
    console.log(...[4,8]);  // 4 8   拆解数组

    let arr1 = [1,3];let arr2 = [5,4];  
    console.log([...arr1,...arr2]); //合并数组

    var [x,y] = [4,8];      //x = 4   y = 8;
    var [x, ...y] = [4, 8,10,36];   //x = 4   y = [8,10,36]

    let [a,b,c] = "ES6";   //a = E ;b = S ;c = 6;
    let xy = [...'ES6']     //xy = ["E", "S", "6"]

    
    
</script>
</html>